import React from "react";
import {
  BrowserRouter as Router,
  Route,
  Switch,
  Redirect,
} from "react-router-dom";
import Login from "./pages/Login/index.jsx";
import NotFound from "./pages/NotFound/index.jsx";
import Register from "./pages/Register/index.jsx";
import Home from "./pages/Home/index.jsx";
export default function App(props) {
  return (
    <Router>
      <Switch>
        <Route path="/login" component={Login} />
        <Route path="/register" component={Register} />
        <Route
          path="/home"
          render={(p) => {
            const token = sessionStorage.getItem("token");
            return token ? (
              <Home />
            ) : (
              <Redirect
                to={{
                  pathname: "/login",
                }}
              />
            );
          }}
        />
        <Route path="/404" component={NotFound} />
        <Redirect to="/login" from="/" exact />
        <Redirect to="/404" />
      </Switch>
    </Router>
  );
}
